package pe.gob.mef.snip.preinversion.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import pe.gob.mef.snip.preinversion.domain.Estudio;
import pe.gob.mef.snip.preinversion.domain.ProyectoBanco;
import pe.gob.mef.snip.preinversion.service.EstudioService;
import pe.gob.mef.snip.preinversion.service.ProyectoBancoService;
import pe.gob.mef.snip.preinversion.util.ServiceException;

@Controller
public class ObservacionesController {

	protected final Log log = LogFactory.getLog(getClass());
	
	@Autowired
	private ProyectoBancoService proyectoBancoService;
	
	private ProyectoBanco proyectoBanco;
	
	@RequestMapping("/observacionSnip03Listar")
	public ModelAndView observacionSnip03Listar(HttpServletRequest request, HttpServletResponse response) {
		
		if (log.isDebugEnabled()) log.debug("observacionSnip03Listar(HttpServletRequest,HttpServletResponse");
	    HttpSession session = request.getSession();	
		Map<String, Object> observacionSnip03Map = new HashMap<String, Object>();
		
	    String viewName = "";
		try{
			
				observacionSnip03Map.put("idProyecto", request.getParameter("idProyecto"));
				observacionSnip03Map.put("version", request.getParameter("version"));
				viewName = "frmObservaciones";			
			
			
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ModelAndView(viewName,"observacionSnip03Map",observacionSnip03Map);
	}
	
	
	@RequestMapping("/observacionSnip03Grabar")
	public ModelAndView observacionSnip03Grabar(HttpServletRequest request, HttpServletResponse response) {
		
		if (log.isDebugEnabled()) log.debug("observacionSnip03Grabar(HttpServletRequest,HttpServletResponse");
	    HttpSession session = request.getSession();	
		Map<String, Object> observacionSnip03Map = new HashMap<String, Object>();
		
		proyectoBanco = new ProyectoBanco();
	    
		String viewName = "";
	       
		try{	
			
			observacionSnip03Map.put("idProyecto", request.getParameter("idProyecto"));
			observacionSnip03Map.put("version", request.getParameter("version"));
				
			
			proyectoBanco.setProyecto(new BigDecimal((String)request.getParameter("idProyecto")));
			proyectoBanco.setVersion(new BigDecimal((String)request.getParameter("version")));
			proyectoBanco.setObservaciones(request.getParameter("ta_observacionProyectoBanco"));
			proyectoBancoService.actualizar(proyectoBanco);
				
				viewName = "frmObservaciones";			
			
		
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ModelAndView(viewName,"observacionSnip03Map",observacionSnip03Map);
		
	}
	
	
	
}

